package com.chen.nongansampling.adapter;

import android.content.Context;

import com.chen.nongansampling.bean.Callback;
import com.chen.nongansampling.bean.TianjiaCaiYnagRequest;
import com.chen.nongansampling.bean.UpdateOperatingRequest;
import com.chen.nongansampling.manager.DataManager;
import com.chen.nongansampling.presenter.BasePresenter;
import com.chen.nongansampling.presenterView.UpdateOperatorView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class UpdateOperatorPresenter extends BasePresenter {
    private Context mContext;
    private UpdateOperatorView updatebaseView;
    private Callback callback;
    public UpdateOperatorPresenter(Context context){
        mContext=context;
    }
    @Override
    public void BindPresentView(Object presentView) {
        updatebaseView = (UpdateOperatorView) presentView;
    }

    public void UpdateOperatorPresenterResponseInfo(UpdateOperatingRequest updateOperatingRequest) {
        DataManager.getInstance(mContext).updateOperatingResponseInfo(updateOperatingRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<Callback>(){
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Callback listCallbackData) {
                        callback = listCallbackData;

                    }


                    @Override
                    public void onError(Throwable e) {
                        updatebaseView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        if (callback != null) {
                            updatebaseView.UpdateOperator(callback);

                        }
                        //                      AddOperatorPresenter.super.compositeDisposable.dispose();
                    }
                });

    }




    //新增样品名称
    public void updateCaiYangResponseInfo(TianjiaCaiYnagRequest tianjiaCaiYnagRequest) {
        DataManager.getInstance(mContext).updateCaiYangResponseInfo(tianjiaCaiYnagRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<Callback>(){
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Callback listCallbackData) {
                        callback = listCallbackData;

                    }


                    @Override
                    public void onError(Throwable e) {
                        updatebaseView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        if (callback != null) {
                            updatebaseView.UpdateOperator(callback);

                        }
                        //                      AddOperatorPresenter.super.compositeDisposable.dispose();
                    }
                });

    }
}
